package cn.wizzer.app.web.modules.controllers.crown;

import cn.wizzer.app.user.modules.models.enums.BizTypeEnum;
import cn.wizzer.app.user.modules.services.account.UserAccountRecordService;
import cn.wizzer.app.web.commons.filter.ApiTokenFilter;
import cn.wizzer.framework.base.Result;
import cn.wizzer.framework.filter.ParamFilter;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.ApiOperation;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.annotation.*;


/**
 * 皇冠流水Controller
 *
 * @author
 */
@At("/api/crown/account")
@IocBean
@Filters({@By(type = ApiTokenFilter.class)})
public class ApiCrownAccountController {

    private static final Log log = Logs.get();

    @Reference
    @Inject
    private UserAccountRecordService accountRecordService;


    @ApiOperation(value = "流水查询", notes = "流水查询", httpMethod = "POST", response = Object.class)
    @At()
    @Ok("json")
    @Filters({@By(type = ApiTokenFilter.class), @By(type = ParamFilter.class)})
    public Object record(
            @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize,
            BizTypeEnum bizType, long startTime, long endTime) {
        String appid = Mvcs.getReq().getHeader("appid");
        Cnd cnd = Cnd.NEW();
        cnd.where().and("user_id", "=", appid);
        cnd.and("biz_type","in",
                "'BALL_DEDUCT','BALL_RESETTLE','BALL_BET','BALL_REVERT','BALL_RESULT','SELF_REBATE','SUB_REBATE','COLLECT','TRANSFER','CASH'");
        cnd.orderBy("ctAt", "desc");
        if (bizType != null) {
            cnd.and("biz_type","=",bizType);
        }
        if (startTime != 0){
            cnd.and("ctAt",">=",startTime);
        }
        if (endTime != 0){
            cnd.and("ctAt","<",endTime);
        }
        return Result.success().addData(accountRecordService.listPage(pageNumber, pageSize, cnd));
    }

}





